# -*- coding : utf_8 -*-
"""
=======================================
Time : 2025/4/10 12:11
Author : 田霄汉
Email : 522989570@qq.com
File : matplotlib_class09.py
Project : pandas_demo
Function : 合并叠加柱状图
=======================================
"""
from config.setting import file_path
import pandas as pd
import matplotlib.pyplot as plt

excel09_path = file_path['excel_path'] + '/excel09.xlsx'
products = pd.read_excel(io=excel09_path,
                         skiprows=3,
                         usecols='C:H',
                         index_col='ID')

# 将合并数据进行排序
products['TOTAL'] = products['2023YEAR'] + products['2024YEAR'] + products['2025YEAR']
# 如果想让横着的图表，从上到下依次递减，就将ascending=True
products.sort_values(by='TOTAL', inplace=True, ascending=True)

# # 如果想把列进行合并数据展示就使用stacked=True
# products.plot.bar(x='BOOK_NUM',
#                   y=['2023YEAR', '2024YEAR', '2025YEAR'],
#                   color=['blue', 'red', 'yellow'],
#                   stacked=True)
# 如果想展示横着的图表就用products.plot.barh()
products.plot.barh(x='BOOK_NUM',
                  y=['2023YEAR', '2024YEAR', '2025YEAR'],
                  color=['blue', 'red', 'yellow'],
                  stacked=True)

# 设置title
plt.title('International Books by Total_Price ', fontsize=16, fontweight='bold')

# 展示figure
plt.tight_layout()
plt.show()
